/**
 * 
 */
package com.googlecode.lohr.parser.combinators.matcher;


import java.util.ArrayList;
import java.util.List;

import com.googlecode.lohr.parser.combinators.MatchResults;
import com.googlecode.lohr.parser.combinators.node.AbstractNode;
import com.googlecode.lohr.parser.combinators.node.StringNode;

/**
 * Matches anything of the given length
 * @author ted stockwell
 */
public class AnyStringMatcher extends Matcher
{
	private int _length;

	public AnyStringMatcher(int length)
	{
		_length= length;
	}

	@Override
	public MatchResults match(MatchContext ctx, int start) 
	{
		String input= ctx.getInput();
		if (input.length()-start < _length)
			return new MatchResults("Expected input of length "+_length, start);
		
		List<AbstractNode> combinedResults = new ArrayList<AbstractNode>();
		combinedResults.add(
				new StringNode(this, start, start+_length, 
						input.substring(start, start+_length)));

		return new MatchResults(combinedResults);
	}
}